package com.tzkyzj.tiremanager.repository;



import com.tzkyzj.tiremanager.entity.TirePhoto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface TirePhotoRepository extends JpaRepository<TirePhoto, Long> {
    List<TirePhoto> findByTireId(Long tireId);
    Optional<TirePhoto> findByIdAndTireId(Long id, Long tireId);
    /**
     * 根据轮胎ID删除照片
     */
    void deleteByTireId(Long tireId);

    // 根据照片类型查询
    List<TirePhoto> findByTireIdAndPhotoType(Long tireId, String photoType);


    @Query("SELECT tp FROM TirePhoto tp WHERE tp.tire.id = :tireId AND tp.photoType IN :photoTypes")
    List<TirePhoto> findByTireIdAndPhotoTypeIn(@Param("tireId") Long tireId, @Param("photoTypes") List<String> photoTypes);

}
